'''
@Author: your name
@Date: 2020-05-14 23:49:43
@LastEditTime: 2020-05-18 18:57:56
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \Gitee\selenium_project\All_Case.py
'''
import unittest
import time
import os
from BeautifulReport import BeautifulReport

# 获取路径1
# 获取项目的路径
curpath = os.path.dirname(os.path.realpath(__file__))
# 获取所有测试用例的路径
casepath = os.path.join(curpath, "testCase")
# 获取测试吧报告的路径
result_dir = os.path.join(curpath, "result")


def add_case(case_path=casepath, rule="TestRegedit*.py"):
    '''加载所有的测试用例'''
    discover = unittest.defaultTestLoader.discover(
        case_path, pattern=rule, top_level_dir=None)
    return discover


def run_case(case):
    result = BeautifulReport(case)
    now = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
    result.report(filename=now, description='xx系统测试报告', report_dir=result_dir)


def start_all():
    # 用例集合
    cases = add_case()
    # 之前是批量执行，这里改成for循环执行
    run_case(cases)


start_all()
# 发送邮件
